<?php
require_once("../../../controllers/init.php");
//echo "Filesystem root = ".$FILE_SYSTEM_ROOT."\n<br>";
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");
//echo "logged on - ".(($IS_LOGGED_ON)?"true\n":"false\n");

//  encoding=\"ISO-8859-1
header ("Content-Type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$events = new EventsResultSet();

$fromDate = new DateTime("now");
$events->setFrom($fromDate);

$toDate = new DateTime("now"); 
$toDate->add(new DateInterval('P1M'));
$events->setTo($toDate); 

// echo "start :".$fromDate->format('Y-m-d H:i')."<br>";
// echo "end :".$toDate->format('Y-m-d H:i')."<br>";

$results = $events->getEvents();
echo "<Events>\n";
foreach ($results as $event) 
{
	echo "<Event>\n<EventID>".htmlentities($event->getEventID())."</EventID>\n";
	echo "<OriginalRecordID>".htmlentities($event->getOriginalRecordID())."</OriginalRecordID>\n";
	echo "<CreatedWhen>".htmlentities($event->getCreatedWhen()->format('Y-m-d H:i'))."</CreatedWhen>\n";
	echo "<CreatedBy>".htmlentities($event->getCreatedBy())."</CreatedBy>\n";
	echo "<DeletedWhen>".htmlentities($event->getDeletedWhen()->format('Y-m-d H:i'))."</DeletedWhen>\n";
	echo "<DeletedBy>".htmlentities($event->getDeletedBy())."</DeletedBy>\n";
	echo "<Start>".htmlentities($event->getStart()->format('Y-m-d H:i'))."</Start>\n";
	echo "<End>".htmlentities($event->getEnd()->format('Y-m-d H:i'))."</End>\n";
	echo "<Title>".htmlentities($event->getTitle())."</Title>\n";
	echo "<Description>".htmlentities($event->getDescription())."</Description>\n";
	echo "<InvolveeLongNames>\n";
	foreach($event->getInvolvees() as $involvee)
	{
		echo "<Involvee>".htmlentities($INVOLVEES[$involvee]['LongName'])."</Involvee>\n";
	}
	echo "</InvolveeLongNames>\n";
	echo "<InvolveeShortNames>\n";
	foreach($event->getInvolvees() as $involvee)
	{
		echo "<Involvee>".htmlentities($INVOLVEES[$involvee]['ShortName'])."</Involvee>\n";
	}
	echo "</InvolveeShortNames>\n";
	echo "<LocationLongNames>\n";
	foreach($event->getLocations() as $location)
	{
		echo "<Location>".htmlentities($LOCATIONS[$location]['LongName'])."</Location>\n";
	}
	echo "</LocationLongNames>\n";
	echo "<LocationShortNames>\n";
	foreach($event->getLocations() as $location)
	{
		echo "<Location>".htmlentities($LOCATIONS[$location]['ShortName'])."</Location>\n";
	}
	echo "</LocationShortNames>\n";
		
	echo "</Event>\n";
}
echo "</Events>\n";

?>